package controller

import (
	"hft/Database/admin"
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"strconv"

	"github.com/gin-gonic/gin"
)

type Advise struct{}

func (*Advise) Add(c *gin.Context) {

	var data *admin.Advise

	var sid, _ = strconv.Atoi(c.Request.Header.Get("sid"))

	if sid == 0 {
		utils.FailWithMessage("该站点尚未开通", c)
		return
	}

	c.ShouldBindJSON(&data)

	data.City = uint(sid)

	services.AdviseService.Add(data)

	utils.Ok(c)
}

func (*Advise) List(c *gin.Context) {

	var data *request.Advise

	c.ShouldBindJSON(&data)

	list, err := services.AdviseService.List(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(list, c)

}

var AdviseController = new(Advise)
